package project.common;

import project.entity.po.User;

import java.util.List;

public class PageInfo {
    private Integer pageNum;
    private Integer pageSize;
    private List<User> list;

    //数据总条数
    private Integer totals;
    //数据总页数
    private Integer pageMaxNum;
    //是否是第一页
    private Boolean first;
    //是否是最后一页
    private Boolean last;
    //是否有下一页
    private Boolean hasNext;
    //是否有上一页
    private Boolean hasPrev;

    public PageInfo() {
    }

    public PageInfo(Integer pageNum, Integer pageSize, List<User> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.list = list;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public List<User> getList() {
        return list;
    }

    public void setList(List<User> list) {
        this.list = list;
    }

    public Integer getPageMaxNum() {
        return pageMaxNum;
    }

    public void setPageMaxNum(Integer pageMaxNum) {
        this.pageMaxNum = pageMaxNum;
    }

    public Integer getTotals() {
        return totals;
    }

    public void setTotals(Integer totals) {
        this.totals = totals;
        this.pageMaxNum = (totals % pageSize == 0) ? totals / pageSize : totals / pageSize + 1;
        this.first = (pageNum == 1);
        this.last = (pageNum == pageMaxNum);
        this.hasNext = !this.last;
        this.hasPrev = !this.first;
    }

    public Boolean getFirst() {
        return first;
    }

    public void setFirst(Boolean first) {
        this.first = first;
    }

    public Boolean getLast() {
        return last;
    }

    public void setLast(Boolean last) {
        this.last = last;
    }

    public Boolean getHasNext() {
        return hasNext;
    }

    public void setHasNext(Boolean hasNext) {
        this.hasNext = hasNext;
    }

    public Boolean getHasPrev() {
        return hasPrev;
    }

    public void setHasPrev(Boolean hasPrev) {
        this.hasPrev = hasPrev;
    }

    @Override
    public String toString() {
        return "PageInfo{" +
                "pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                ", first=" + first +
                ", last=" + last +
                ", hasPrev=" + hasPrev +
                ", hasNext=" + hasNext + "\n" +
                ", list=" + list +
                '}';
    }
}
